﻿#include "FITKAbaLoadConcentratedForce.h"
#include "FITKAbaStepManager.h"
#include "FITK_Kernel/FITKCore/FITKDataRepo.h"
#include "FITK_Interface/FITKInterfaceModel/FITKCoordinateSystem.h"


double Interface::ConcentratedLoadData::getValue1() const
{
    return m_value1;
}

double Interface::ConcentratedLoadData::getValue2() const
{
    return m_value2;
}

double Interface::ConcentratedLoadData::getValue3() const
{
    return m_value3;
}

int Interface::ConcentratedLoadData::getAmplitudeId() const
{
    return m_AmplitudeId;
}

void Interface::ConcentratedLoadData::setValue1(double value)
{
    m_value1 = value;
}

void Interface::ConcentratedLoadData::setValue2(double value)
{
    m_value2 = value;
}

void Interface::ConcentratedLoadData::setValue3(double value)
{
    m_value3 = value;
}

void Interface::ConcentratedLoadData::setAmplitudeId(int id)
{
    m_AmplitudeId = id;
}

bool Interface::ConcentratedLoadData::operator==(const ConcentratedLoadData data) const
{
    if (m_value1 == data.m_value1 && m_value2 == data.m_value2 && m_value3 == data.m_value3 && m_AmplitudeId == data.m_AmplitudeId)
        return true;
    return false;
}

Interface::FITKAbaLoadConcentratedForce::FITKAbaLoadConcentratedForce()
{

}

Interface::FITKAbaAbstractLoad::FITKAbaLoadType Interface::FITKAbaLoadConcentratedForce::getLoadType() const
{
    return Interface::FITKAbaAbstractLoad::FITKAbaLoadType::ConcentratedForce;
}

bool Interface::FITKAbaLoadConcentratedForce::isModifiedInStep(int stepId) const
{
    if (!m_modifiedData.contains(stepId))
        return false;
    return true;
}

void Interface::FITKAbaLoadConcentratedForce::activeStateChanged()
{
    if (m_deactiveStepId == -1)
        return;
    //访问当前算例的分析步管理器，获取分析步顺序id列表。
    QVector<int> stepIds = this->getStepIds();
    int index = stepIds.indexOf(m_deactiveStepId);
    if (index == -1)
        return;
    for (int i = index ; i < stepIds.count(); ++i)
    {
        int id = stepIds[i];
        if (m_modifiedData.contains(id))
            m_modifiedData.remove(id);
    }
}

bool Interface::FITKAbaLoadConcentratedForce::copy(FITKAbstractDataObject *obj)
{
    bool ok = FITKAbaAbstractLoad::copy(obj);
    if (!ok)
        return false;
    FITKAbaLoadConcentratedForce* force = dynamic_cast<FITKAbaLoadConcentratedForce*>(obj);
    if (force == nullptr)
        return false;
    this->setDataObjectName(force->getDataObjectName());
    this->m_analyticalFieldId = force->m_analyticalFieldId;
    this->m_csysId = force->m_csysId;
    this->m_data = force->m_data;
    this->m_modifiedData = force->m_modifiedData;
    this->m_flowNodalRotation = force->m_flowNodalRotation;
    return true;
}

double Interface::FITKAbaLoadConcentratedForce::getCF1(int stepId)
{
    return this->getDataInStep(stepId).getValue1();
}

double Interface::FITKAbaLoadConcentratedForce::getCF2(int stepId)
{
    return this->getDataInStep(stepId).getValue2();
}

double Interface::FITKAbaLoadConcentratedForce::getCF3(int stepId)
{
    return this->getDataInStep(stepId).getValue3();
}
 

bool Interface::FITKAbaLoadConcentratedForce::getFlowNodalRotation() const
{
    return m_flowNodalRotation;
}

int Interface::FITKAbaLoadConcentratedForce::getAnalyticalFieldId() const
{
    return m_analyticalFieldId;
}

int Interface::FITKAbaLoadConcentratedForce::getCsysId() const
{
    return m_csysId;
}

Interface::FITKCoordinateSystem* Interface::FITKAbaLoadConcentratedForce::getCsysObj()
{
    if (m_csysId < 0) return nullptr;
    return FITKDATAREPO->getTDataByID<FITKCoordinateSystem>(m_csysId);
}

int Interface::FITKAbaLoadConcentratedForce::getAmplitudeId(int stepId)
{
    return this->getDataInStep(stepId).getAmplitudeId();
}

void Interface::FITKAbaLoadConcentratedForce::setCF1(double value, int stepId)
{
    if (stepId <= 0 || stepId == m_createdStepId)
        m_data.setValue1(value);
    else
    {
        if (!m_modifiedData.contains(stepId))
            m_modifiedData[stepId] = this->getDataInStep(stepId);
        m_modifiedData[stepId].setValue1(value);
    }
}

void Interface::FITKAbaLoadConcentratedForce::setCF2(double value, int stepId)
{
    if (stepId <= 0 || stepId == m_createdStepId)
        m_data.setValue2(value);
    else
    {
        if (!m_modifiedData.contains(stepId))
            m_modifiedData[stepId] = this->getDataInStep(stepId);
        m_modifiedData[stepId].setValue2(value);
    }
}

void Interface::FITKAbaLoadConcentratedForce::setCF3(double value, int stepId)
{
    if (stepId <= 0 || stepId == m_createdStepId)
        m_data.setValue3(value);
    else
    {
        if (!m_modifiedData.contains(stepId))
            m_modifiedData[stepId] = this->getDataInStep(stepId);
        m_modifiedData[stepId].setValue3(value);
    }
}

void Interface::FITKAbaLoadConcentratedForce::setAmplitudeId(int id, int stepId)
{
    if (stepId <= 0 || stepId == m_createdStepId)
        m_data.setAmplitudeId(id);
    else
    {
        if (!m_modifiedData.contains(stepId))
            m_modifiedData[stepId] = this->getDataInStep(stepId);
        m_modifiedData[stepId].setAmplitudeId(id);
    }
}

void Interface::FITKAbaLoadConcentratedForce::setAnalyticalFieldId(int id)
{
    m_analyticalFieldId = id;
}

void Interface::FITKAbaLoadConcentratedForce::setCsysId(int id)
{
    m_csysId = id;
}

void Interface::FITKAbaLoadConcentratedForce::setFlowNodalRotation(bool stat)
{
    m_flowNodalRotation = stat;
}

Interface::ConcentratedLoadData Interface::FITKAbaLoadConcentratedForce::getDataInStep(int stepId)
{
    if (stepId <= 0 || stepId == m_createdStepId)
        return m_data;
    if (m_modifiedData.contains(stepId))
        return m_modifiedData[stepId];
    QVector<int> stepIds = this->getStepIds();
    int createdStepIndex = stepIds.indexOf(m_createdStepId);
    int stepIndex = stepIds.indexOf(stepId);
    if (!(createdStepIndex >= 0 && createdStepIndex < stepIds.size()))
        return m_data;
    if (!(stepIndex >= 0 && stepIndex < stepIds.size()))
        return m_data;
    for (int i = stepIndex; i >= createdStepIndex; --i)
    {
        int id = stepIds.at(i);
        if (m_modifiedData.contains(id))
            return m_modifiedData[id];
    }
    return m_data;
}

 
